package rtda

import (
	"gvm/rtda/heap"
)

type JThread struct {
	pc     int     // 下一条需要执行的字节码指令的地址
	jStack *JStack //线程堆栈
}

func NewJThread() *JThread {
	return &JThread{
		jStack: NewJStack(1024),
	}
}

func (self *JThread) PushJFrame(frame *JFrame) {
	self.jStack.push(frame)
}

func (self *JThread) PopJFrame() *JFrame {
	return self.jStack.pop()
}

func (self *JThread) TopJFrame() *JFrame {
	return self.jStack.top()
}

func (self *JThread) CurJFrame() *JFrame {
	return self.jStack.top()
}

func (self *JThread) PC() int {
	return self.pc
}

func (self *JThread) SetPc(pc int) {
	self.pc = pc
}

func (self *JThread) NewFrame(method *heap.Method) *JFrame {
	return newJFrame(self, method)
}

func (self *JThread) IsStackEmpty() bool {
	return self.jStack.isEmpty()
}

func (self *JThread) ClearStack() {
	self.jStack.clear()
}

func (self *JThread) GetJFrames() []*JFrame {
	return self.jStack.getFrames()
}

func (jt *JThread) CurrentJFrame() *JFrame {
	return jt.jStack.top()
}
